﻿using ruleEngineDemo.engine.factory.product;

namespace ruleEngineDemo.engine.factory
{
    /// <summary>
    /// 工厂入口
    /// </summary>
    public class EngineFactory
    {
        private IServiceProvider _serviceProvider;

        public EngineFactory(IServiceProvider serviceProvider)
        {
            _serviceProvider = serviceProvider;
        }

        /// <summary>
        /// 获取新的工厂类
        /// </summary>
        /// <param name="factoryName"></param>
        /// <returns></returns>
        public AbstractEngineFactory? New(Type factoryName)
        {
            var factorys = _serviceProvider.GetServices <AbstractEngineFactory>();
            foreach(var factory in factorys)
            {
                if (factory.GetType() == factoryName)
                    return factory;
            }
            return null;
        }
    }
}
